﻿using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;

namespace WalkingTec.Mvvm.Core
{
	public static class BaseCRUDVMExtension
	{
		public static T GetPureEntityById<T>(this BaseCRUDVM<T> self, object id) where T : TopBasePoco, new()
		{
			var val = self.DC.Set<T>().AsNoTracking().CheckID(id).FirstOrDefault();
			if (val == null)
			{
				throw new Exception("数据不存在");
			}
			else
			{
				self.Entity = val;
				return val;
			}
		}
	}
}
